package org.vacoor.xqq;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
 * ��ͬƽ̨�Ͱ汾�£�Mbeans���ֲ�һ����Ϊwin32+jdk 7_b07
 * Author:Դ������
 * Date:2012-12-9 ����7:18:29
 */
public class MBeanAccess {
	public static void main(String[] args) throws Exception {
		/*
		//��ӡGC����
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName youngMBean = new ObjectName("java.lang:type=GarbageCollector,name=MarkSweepCompact");
		ObjectName tenuredMBean = new ObjectName("java.lang:type=GarbageCollector,name=Copy");
		System.out.println("YGC:" + mbs.getAttribute(youngMBean, "CollectionCount"));
		System.out.println("FGC:" + mbs.getAttribute(tenuredMBean, "CollectionCount"));
		System.gc();
		System.out.println("YGC:" + mbs.getAttribute(youngMBean, "CollectionCount"));
		System.out.println("FGC:" + mbs.getAttribute(tenuredMBean, "CollectionCount"));
		*/
//		int pid = getPid();
//        System.out.println("pid: " + pid);
        //System.in.read(); // block the program so that we can do some probing on it  
		Thread.sleep(1000 * 60);

        new Object(){
            @Override
            protected void finalize() throws Throwable {
                System.out.println("finalize");
            }
        };
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
//                System.gc();
                System.out.println("run");
            }
        });
    }
	
	private static int getPid() { 
		//��ȡ��̵�PID
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
        String name = runtime.getName(); // format: "pid@hostname"  
        try {  
            return Integer.parseInt(name.substring(0, name.indexOf('@')));  
        } catch (Exception e) {  
            return -1;  
        }  
    }


}

